package com.earth.c.plugins.shiro;

import java.util.concurrent.atomic.AtomicInteger;

import org.apache.shiro.session.Session;
import org.apache.shiro.session.SessionListener;
import org.springframework.stereotype.Component;

import lombok.extern.slf4j.Slf4j;

@Slf4j
@Component
public class ShiroSessionListener implements SessionListener {

	private final AtomicInteger sessionCount = new AtomicInteger(0);

	@Override
	public void onStart(Session session) {
		sessionCount.incrementAndGet();
		log.debug("当前在线人数(登录成功+1)：%s", sessionCount.get());
	}

	@Override
	public void onStop(Session session) {
		sessionCount.decrementAndGet();
		log.debug("当前在线人数(退出登录-1)：%s", sessionCount.get());
	}

	@Override
	public void onExpiration(Session session) {
		sessionCount.decrementAndGet();
		log.debug("当前在线人数(登陆过期-1)：%s", sessionCount.get());
	}

}
